import request from '@/utils/apiRequest'

// 获取所有销售订单
export function getSalesOrders() {
  return request({
    url: '/SalesOrders',
    method: 'get'
  })
}

// 获取销售订单详情
export function getSalesOrder(id) {
  return request({
    url: `/SalesOrders/${id}`,
    method: 'get'
  })
}

// 创建销售订单
export function createSalesOrder(data) {
  return request({
    url: '/SalesOrders',
    method: 'post',
    data
  })
}

// 更新销售订单
export function updateSalesOrder(id, data) {
  return request({
    url: `/SalesOrders/${id}`,
    method: 'put',
    data
  })
}

// 审核销售订单
export function approveSalesOrder(id, approvedBy) {
  return request({
    url: `/api/SalesOrders/${id}/approve`,
    method: 'put',
    params: {
      approvedBy
    }
  })
}

// 关闭销售订单
export function closeSalesOrder(id, closedBy, reason) {
  return request({
    url: `/api/SalesOrders/${id}/close`,
    method: 'put',
    params: {
      closedBy,
      reason
    }
  })
}

// 删除销售订单
export function deleteSalesOrder(id) {
  return request({
    url: `/api/SalesOrders/${id}`,
    method: 'delete'
  })
}

// 搜索销售订单
export function searchSalesOrders(keyword = null, customerId = null, status = null) {
  return request({
    url: '/SalesOrders/search',
    method: 'get',
    params: {
      keyword,
      customerId,
      status
    }
  })
}